#!/usr/bin/perl

=head1 NAME

AFX::Visual - AuditFX Visual.

=head1 COPYRIGHT AND LICENSE

Copyright (C) 2010 Mikhail Volkov

This file is part of AuditFX.

    AuditFX is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    AuditFX is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with AuditFX.  If not, see <http://www.gnu.org/licenses/>.
=cut

##############################################################################
# Globals
#

use lib 'lib';
use strict;
use warnings;

use Getopt::Std;

use AFX::ACF;
use AFX::ASF;

## Try to use Wx library
eval "use Wx";
if ($@) {
    print "Failed loading Wx library. Error: $@\n";
    die $@;
}

## Try to use Process library
eval "use AFX::Process";
if ($@) {
    print "Failed loading AFX::Process library. Error: $@\n";
    die $@;
}

## Try to use Visual library
eval "use AFX::Visual";
if ($@) {
    print "Failed loading AFX::Visual library. Error: $@\n";
    die $@;
}

## Execute main script
visual();

##############################################################################
#
# visual()
#

sub visual {

## Open ACF
    my $acf = new AFX::ACF();

## Open Main ASF
    my $asf = new AFX::ASF( $acf, $acf->open_sitefile() );

## Exit with exception: ASF processing error
    if ( !$asf ) {

## Set Error status
        my $status = 1;

## Exit with status
        exit($status);
    }

## Create Process
    my $process = new AFX::Process( $acf, $asf, 'visual' );

## If process wasn't created
    if ( !$process ) {

## Print process failed message
        $acf->message_failed_process();

## Set Error status
        my $status = 1;

## Exit with status
        exit($status);
    }

## Set default site_mach
    my $site_mach = 'LNX';

## Get default machine for specified
    my $machine_default = $acf->get_machine($site_mach);

## Check default machine exist in ACF
    if ( !$machine_default ) {

## Print Not supported unit
        $acf->message_failed_unit($site_mach);

## Set Error status
        my $status = 1;

## Exit with status
        exit($status);
    }

## Create new ARF
    my $arf = new AFX::ARF( $process, $machine_default );

## Set Normal status
    my $status = 0;

## Create Wx application
    my $wxapp = Wx::SimpleApp->new;

## Set locale
    my $locale = Wx::Locale->new( Wx::Locale::GetSystemLanguage() );

## Create mainframe
    AFX::Visual->new( $process, $arf );

## Run Wx application
    $wxapp->MainLoop;

## Exit with status
    exit($status);

} ## end sub visual
